package com.lp.search.config;

import com.lp.model.constants.MQConstants;
import org.elasticsearch.common.inject.BindingAnnotation;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {

    @Bean
    public DirectExchange esDirectExchange() {
        return new DirectExchange(MQConstants.ES_EXCHANGE_DIRECT, true, false);
    }

    @Bean
    public Queue insertArticleQueue() {
        return new Queue(MQConstants.ES_ARTICLE_INSERT_QUEUE, true);
    }

    @Bean
    public Binding insertArticleBind() {
        return BindingBuilder.bind(insertArticleQueue()).to(esDirectExchange())
                .with(MQConstants.ES_ARTICLE_INSERT_QUEUE);
    }

    @Bean
    public Queue delArticleQueue() {
        return new Queue(MQConstants.ES_ARTICLE_DEL_QUEUE, true);
    }

    @Bean
    public Binding delArticleBind() {
        return BindingBuilder.bind(delArticleQueue()).to(esDirectExchange())
                .with(MQConstants.ES_ARTICLE_DEL_QUEUE);
    }

    @Bean
    public Queue updateArticleQueue() {
        return new Queue(MQConstants.ES_ARTICLE_UPDATE_QUEUE, true);
    }

    @Bean
    public Binding updateArticleBind() {
        return BindingBuilder.bind(updateArticleQueue()).to(esDirectExchange())
                .with(MQConstants.ES_ARTICLE_UPDATE_QUEUE);
    }

    @Bean
    public Queue userUpdateQueue() {
        return new Queue(MQConstants.ES_USER_UPDATE_QUEUE, true);
    }

    @Bean
    public Binding userUpdateBind() {
        return BindingBuilder.bind(userUpdateQueue()).to(esDirectExchange())
                .with(MQConstants.ES_USER_UPDATE_QUEUE);
    }

}
